﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BXH.Movie.Bll;
using BXH.Movie.Model;
using CCWin;

namespace BXH.Movie.Forms
{
    public partial class UCInformationManager : UserControl
    {
        private UserInfoService userInfoService = new UserInfoService();
        public UCInformationManager()
        {
            InitializeComponent();
            this.Load += UCInformationManager_Load;
        }

        private void UCInformationManager_Load(object sender, EventArgs e)
        {
            var userInfo = Program.LoginUser;
            txtId.Text = userInfo.Id.ToString();
            txtCode.Text = userInfo.UserCode;
            txtAge.Text = userInfo.Age.ToString();
            txtName.Text = userInfo.UserName;
            txtNick.Text = userInfo.UserNick;
            switch (userInfo.RoleId)
            {
                case RoleType.Admin:
                    txtRole.Text = "管理员";
                    break;
                case RoleType.Administrator:
                    txtRole.Text = "超级管理员";
                    break;
                case RoleType.User:
                    txtRole.Text = "用户";
                    break;
            }
            switch (userInfo.Sex)
            {
                case 0:
                    rbtnMan.Checked = true;
                    rbtnWoMan.Checked = false;
                    break;
                case 1:
                    rbtnWoMan.Checked = true;
                    rbtnMan.Checked = false;
                    break;
            }


        }

        private void btnUpdate_CheckedChanged(object sender, EventArgs e)
        {
            txtAge.ReadOnly =
            txtName.ReadOnly =
            txtNick.ReadOnly = false;
        }

        private void btnSave_CheckedChanged(object sender, EventArgs e)
        {
            txtAge.ReadOnly =
            txtName.ReadOnly =
            txtNick.ReadOnly = true;
            int age = 0;
            if (!int.TryParse(txtAge.Text.Trim(), out age))
            {
                MessageBoxEx.Show("年龄格式不正确");
            }
            Program.LoginUser.Age = age;
            Program.LoginUser.UserName = txtName.Text.Trim();
            Program.LoginUser.UserNick = txtNick.Text.Trim();
            userInfoService.Update(Program.LoginUser);
        }
    }
}
